<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<link rel="icon" href="https://v3.bootcss.com/favicon.ico">
		<title>文章修改</title>
		<link href="/css/bootstrap/bootstrap.min.css" rel="stylesheet">
		<link href="/css/page/blog.css" rel="stylesheet">
		<link href="/css/markdown/simplemde.min.css" rel="stylesheet">
		<link href="/css/font-awesome.min.css" rel="stylesheet">
	</head>

	<body>

		<#include "/nav.ftl"/>

		<div class="container">
			<div class="row" style="padding-top: 20px">
				<form class="form-horizontal" id="form_save">
					<input type="hidden" name="id" value="${article.id}">
					<div class="form-group">
						<label for="ipt_title" class="col-sm-2 control-label">标题</label>
						<div class="col-sm-10">
							<input type="text" maxlength="20" name="title" class="form-control notEmpty" value="${article.title}" id="ipt_title" placeholder="标题">
						</div>
					</div>
					<div class="form-group">
						<label for="ipt_brief " class="col-sm-2 control-label">简介</label>
						<div class="col-sm-10">
							<input type="text" maxlength="30" name="brief" class="form-control notEmpty" value="${article.brief}" id="ipt_brief" placeholder="简介">
						</div>
					</div>
					<div class="form-group">
						<label for="ipt_brief " class="col-sm-2 control-label">内容</label>
						<div class="col-sm-10">
							<textarea id="textarea_content" name="content" class="form-control">${article.content}</textarea>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<button type="button" onclick="save()" class="btn btn-default">保存</button>
						</div>
					</div>
				</form>
			</div>
			<!-- /.row -->

		</div>
		<!-- /.container -->
		<#include "/foot.ftl"/>
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/bootstrap.min.js"></script>
		<script type="text/javascript" src="/js/bootstrap/plugins/bootbox.js"></script>
		<script type="text/javascript" src="/js/common/common.js"></script>
		<script type="text/javascript" src="/js/common/myValidation.js"></script>
		<script type="text/javascript" src="/js/markdown/simplemde.min.js"></script>
		<script type="text/javascript">
			var simplemde = new SimpleMDE({
				element: $("#textarea_content")[0],
				autoDownloadFontAwesome:false,
				spellChecker: false
			});
			var redirectUrl = "${redirectUrl}";
			function save(){
				var validResult = myValidation.commonValid("form_save", {
					showInfo : function(ele, mes) {
						bootbox.alert(mes);
					}
				});
				if (!validResult) {
					return;
				}
				var content = simplemde.value();
				if(content.trim().length == 0){
					bootbox.alert("请输入内容");
				}
				$("#textarea_content").val(content);
				$.post("/article/edit",$("#form_save").serialize(), function(result){
					if(result.code == 200){
						bootbox.alert("修改成功", function(){
							location.href= redirectUrl;
						});
					}else{
						bootbox.alert(result.mes);
					}
				})
			}
		
		</script>
	</body>

</html>